package com.ytq.secutiry.config.handler;

import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author yuantongqin
 * desc: 权限处理成功
 * 2020-09-30
 *
 * 根据当前Security是中是否有authentication对象，来判断验证是否成功
 *  SecurityContextHolder.getContext().setAuthentication(authentication);
 */
@Component
public class SuccessHandlerRequest implements AuthenticationSuccessHandler {


    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {

        // 成功之后
        System.out.println("处理请求成功");

        response.setCharacterEncoding("utf-8");
        response.getWriter().write("处理请求成功");

    }
}
